/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Welcome;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextBox;

/**
 *
 * @author SamSung
 */
class InsertAnswer implements CommandListener {

    private TextBox textBox;
    private Command back, ok;
    private Start midlet;

    public InsertAnswer(Start midlet) {
        this.midlet = midlet;
    }

    public TextBox insertAnswer(String title) {
        textBox = new TextBox(title, "", 256, 0);
        back = new Command("Trở lại", Command.BACK, 1);
        ok = new Command("OK", Command.OK, 1);
        textBox.addCommand(back);
        textBox.addCommand(ok);
        textBox.setCommandListener(this);
        return textBox;
    }

    public void commandAction(Command c, Displayable d) {
        String label = c.getLabel();
        if (label.equals("Trở lại")) {
            DrawChoice.ans = false;
            DrawChoice.bigAnswer = false;
            midlet.disManager.popDisplayable();
            midlet.disManager.popDisplayable();
        } else {
            if (textBox.getString().equals("")) {
                Alert notify = new Alert("", "Bạn không nên để trống câu trả lời", null, AlertType.INFO);
                notify.setTimeout(1000);
                midlet.getDis().setCurrent(notify);
            } else {
                if (!DrawChoice.bigAnswer) {
                    DrawChoice.ans = true;
                }
                PassTextboxText.setTextBoxText(textBox.getString());
                midlet.disManager.popDisplayable();
            }
        }
    }
}
